import os
import shutil


def copyFile(oldpath, newpath, classNum, _flag):
    if not os.path.exists(newpath):
        os.mkdir(newpath)
    file_list = os.listdir(oldpath)
    num = 0
    if _flag == 'xml':
        for _file in file_list:
            num +=1
            newfile_name = classNum + '_' + str(num) + '.xml'
            newfile_path = os.path.join(newpath, newfile_name)
            shutil.copy(os.path.join(oldpath, _file), newfile_path)
    else:
        for _file in file_list:
            num += 1
            newfile_name = classNum + '_' + str(num) + '.jpg'
            newfile_path = os.path.join(newpath, newfile_name)
            shutil.copy(os.path.join(oldpath, _file), newfile_path)


new03xml_path = '/Users/jiangce/Desktop/03xml'
new04xml_path = '/Users/jiangce/Desktop/04xml'
new03images_path = '/Users/jiangce/Desktop/03'
new04images_path = '/Users/jiangce/Desktop/04'
xml03_path = '/Users/jiangce/Desktop/0304图片标记/03'
images03_path = '/Users/jiangce/Desktop/0304图片标记/003'
xml04_path = '/Users/jiangce/Desktop/0304图片标记/04'
images04_path = '/Users/jiangce/Desktop/0304图片标记/004'

classNum = str(0) + str(3)
copyFile(xml03_path, new03xml_path, classNum, 'xml')
copyFile(images03_path, new03images_path, classNum, 'jpg')

classNum = str(0) + str(4)
copyFile(xml03_path, new04xml_path, classNum, 'xml')
copyFile(images04_path, new04images_path, classNum, 'jpg')